#include "Timer.hpp"

#include "Common.hpp"

#include "Camera.hpp"

#include "Scene.hpp"

#include "UserInterface.hpp"
#include "Context.hpp"
#include "Player.hpp"

extern void displayFunc();

void Timer::init()
{
  m_updateViewMatrixRate = 20;
  glutTimerFunc(m_updateViewMatrixRate, Timer::updateViewMatrix, 0);
  
  glutTimerFunc(20, Timer::refresh, 0);
}

void Timer::updateViewMatrix(int)
{
  g_context.getUpdater()->update();
  g_context.m_scene->m_player->update();
  if(g_context.m_scene->m_segway->m_mounted || g_context.m_scene->m_segway->m_hspeed 
      || g_context.m_scene->m_segway->m_vspeed == 0)
  g_context.m_scene->m_segway->update();
  g_context.m_camera->updateView();
  glutTimerFunc(m_updateViewMatrixRate, Timer::updateViewMatrix, 0);
}

void Timer::refresh(int)
{
  glutPostRedisplay();
  glutTimerFunc(20, Timer::refresh, 0);
}

int Timer::m_updateViewMatrixRate;